<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class DeviceInfo extends Model
{
    const REMIND_LIMIT = 5;

    public $fillable = [
        'device_id',
		'TDS1',
        'TDS2',
    	'dec_status',
    	'effluent_status',
    	'water_temperature',
        'filter_cnt1',
        'filter_set1',
        'filter_cnt2',
        'filter_set2',
        'water_cnt',
        'water_time',
        'daily_water_consumption',
        ];

    public function device()
    {
        return $this->belongsTo('App\Models\Device', 'device_id', 'id');
    }

    //缺水
    const HYDROPENIA = 2;

    //检修
    const OVERHAUL = 4;

    protected $appends = [
        'device_status_description',
    ];

    public static $_DEVICE_STATUS_DESCRIPTION = [
        0 => '正常',
        1 => '正常',
        self::HYDROPENIA => '缺水',
        3 => '正常',
        self::OVERHAUL => '检修',
        5 => '正常',
        6 => '正常',
        7 => '正常',
        8 => '漏水',
    ];

    public function getDeviceStatusDescriptionAttribute()
    {
        if(array_key_exists('dec_status', $this->attributes))
        {
            return self::$_DEVICE_STATUS_DESCRIPTION[$this->attributes['dec_status']];
        }
    }

}
